//
//  YJCTabBarController.m
//  xiangzhe
//
//  Created by lyt on 16/11/7.
//  Copyright © 2016年 com.dazhebao. All rights reserved.
//

#import "YJCTabBarController.h"
#import "YJCShareController.h"
#import "YJCMineController.h"
#import "YJCFriendController.h"
#import "YJCCompareController.h"
#import "YJCDiscoverViewController.h"
#import "YJCNavgationController.h"
#import "UIColor+YJCColor.h"
#import "YJCShareBtn.h"
#import "YJCVisitorController.h"


@interface YJCTabBarController ()<UITabBarControllerDelegate>
{
    YJCShareBtn *_shareBtn;
}
@end

@implementation YJCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    [[UITabBar appearance] setBarTintColor:[UIColor yt_colorWithHexString:@"#333333"]];
    self.tabBar.tintColor = [UIColor yt_colorWithHexString:@"#FF3566"];
    [self setupChildVC];
    
}
#pragma mark - 创建子控制器
- (void)setupChildVC{
    UINavigationController *NavDiscover = [[YJCNavgationController alloc] initWithRootViewController:[[YJCDiscoverViewController alloc] init]];
    NavDiscover.title = @"发现";
    NavDiscover.tabBarItem.image = [UIImage imageNamed:@"ic_home"];
    NavDiscover.tabBarItem.selectedImage = [UIImage imageNamed:@"ic_home_hov"];
    
    UINavigationController *NavCompare = [[YJCNavgationController alloc] initWithRootViewController:[[YJCCompareController alloc] init]];
    NavCompare.title = @"参考图";
    NavCompare.tabBarItem.image = [UIImage imageNamed:@"ic_dymic"];
    NavCompare.tabBarItem.selectedImage = [UIImage imageNamed:@"ic_dymic_hov"];
    
    UINavigationController *NavShare = [[YJCNavgationController alloc] initWithRootViewController:[[YJCShareController alloc] init]];
     NavShare.title = @"分享";
    
    UINavigationController *NavFriend = [[YJCNavgationController alloc] initWithRootViewController:[[YJCFriendController alloc] init]];
    NavFriend.title = @"好友";
    NavFriend.tabBarItem.image = [UIImage imageNamed:@"ic_friend"];
    NavFriend.tabBarItem.selectedImage = [UIImage imageNamed:@"ic_friend_hov"];
    
    UINavigationController *NavMine = [[YJCNavgationController alloc] initWithRootViewController:[[YJCMineController alloc] init]];
    NavMine.title = @"我";
    NavMine.tabBarItem.image = [UIImage imageNamed:@"ic_wo"];
    NavMine.tabBarItem.selectedImage = [UIImage imageNamed:@"ic_wo_hov"];
    
    self.viewControllers = @[NavDiscover,NavCompare,NavShare,NavFriend,NavMine];
    // 分享按钮
    YJCShareBtn *shareBtn = [YJCShareBtn buttonWithType:UIButtonTypeCustom];
    _shareBtn = shareBtn;
    [shareBtn setBackgroundImage:[UIImage imageNamed:@"ic_share_hov"] forState:UIControlStateNormal];
    [shareBtn setImage:[UIImage imageNamed:@"ic_share_icon"] forState:UIControlStateNormal];
    [shareBtn sizeToFit];
    
    shareBtn.frame = CGRectMake((self.tabBar.bounds.size.width - 50) / 2, -20, 50, 50);
    [shareBtn addTarget:self action:@selector(turnPicture:) forControlEvents:UIControlEventTouchUpInside];
    [self.tabBar addSubview:shareBtn];
    
    self.delegate = self;
}
#pragma mark - 底部旋转按钮
- (void)turnPicture:(UIButton *)btn{
    self.selectedIndex = 2;
 
    [UIView animateWithDuration:0.5 animations:^{
        
        btn.imageView.transform = CGAffineTransformRotate(btn.imageView.transform, M_PI);
    }];
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    if (self.selectedIndex == 2) {
        [self turnPicture:_shareBtn];

        UINavigationController *loginVC = [[UINavigationController alloc] initWithRootViewController:[[YJCVisitorController alloc] init]];

[self presentViewController:loginVC animated:YES completion:^{
    
}];
//        YJCVisitorController *loginVC = [[YJCVisitorController alloc] init];
//        [self.navigationController pushViewController:loginVC animated:YES];
    }

}

@end
